import time
from pyecharts.charts import Geo
from pyecharts import options
from pyecharts.globals import GeoType


def plotSatPos(satPos):
    '''
    satPos      # 卫星位置dataframe
    '''

    start = time.time()

    g = Geo().add_schema(maptype="world")
    PRN=satPos.iloc[0]['PRN']
    year=satPos.iloc[0]['epoch'].year
    month=satPos.iloc[0]['epoch'].month
    day=satPos.iloc[1440]['epoch'].day
    dataPair = [(satPos.iloc[i]['epoch'],1) for i in range(len(satPos))]

    for i in range(len(satPos)):
        g.add_coordinate(satPos['epoch'][i],satPos['L'][i],satPos['B'][i])

    # 画图
    g.add('',dataPair, type_=GeoType.EFFECT_SCATTER, symbol_size=1.3,color='red')
    g.set_series_opts(label_opts=options.LabelOpts(is_show=False))
    g.set_global_opts(title_opts=options.TitleOpts(title=PRN+' 星下点轨迹 ( '+str(year)+'-'+str(month)+'-'+str(day)+' )'))
    # 保存结果到 html
    result = g.render('data\satPos_'+PRN+'.html')

    finish = time.time()     # Time of finish

    print("Plotting satellite position of ", PRN," is cost in", "{0:.2f}".format(finish-start), "seconds.")

    return result